import React from 'react'
import useStorage from '@/hooks/useStorage'
import {useLocation,Navigate} from 'react-router-dom'
import {Modal} from 'antd'
export default function Auth({children}) {
  const [,,getToken]=useStorage('token')
  const location=useLocation()
  //定义白名单
  let whiteList=['/login']
  const token=getToken()
  if(token){
   
    if(location.pathname=="/login"){
      
      return <Navigate to="/home"></Navigate>
    }
    return <div>{children}</div>
  }else{
    if(whiteList.includes(location.pathname)){
        return <>{children}</>
    }else{
        return <Navigate to="/login"></Navigate>
    }
  }
}
